﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Wicresoft.UnifyShow.Business;

namespace Wicresoft.UnifyShow.Portal.Controllers
{
    public class AdminDocumentController : Controller
    {

        [HttpPost]
        public ActionResult Admin(string name)
        {
            DocumentHelper.InsertFile(Request.Files[0], name, User.Identity.Name);
            return View();
        }

        public ActionResult DownLoad(int id)
        {
            byte[] files;
            string type, filename;
            DocumentHelper.GetFile(id, out files, out type, out filename);
            return File(files, type, filename);
        }

        [Authorize]
        public ActionResult Admin()
        {
            return View();
        }

        public ActionResult ListAdmin()
        {
            return PartialView(DocumentHelper.GetList().OrderByDescending(o => o.CreateTime).ToList());
        }

        public ActionResult List()
        {
            return PartialView(DocumentHelper.GetList().OrderByDescending(o=>o.CreateTime).ToList());
        }

        [HttpPost]
        public ActionResult Delete(int id)
        {
            DocumentHelper.DeleteFile(id);
            return new EmptyResult();
        }
    }
}
